<?php
//字符集
header('content-type:text/html;charset=utf-8');
//连接增产改查轮子
include './login_CRUD.php';
//连接数据库
$coon = connectDB('127.0.0.1','root','qq553408','test2106');
//获取表单数据
$bname = $_GET["bname"];//书名
$bid = $_GET["bid"];//书id
$username = $_GET["username"];//当前登陆用户

//查询login表单 这个用户有没有这本书
$sql = "SELECT *FROM books WHERE `bid` ='$bid' AND `username` = '$username'"; 
$res = mysqli_query($coon,$sql);

//测试连接数据库连接失败
if(!$coon){
    die('error for mysql: ' . mysqli_error($coon));
}
//连接成功
else{
    //bid比对结果
    $row = mysqli_fetch_assoc($res);    
    // 当结果为数据库没有
    if (!$row&&$bid!=""&&$username!="") {
        $regSql = " INSERT INTO books(`bid`,`bname`,`username`) value('$bid','$bname','$username') ";
        mysqli_query($coon,$regSql);
        // 回传bid
        echo $bid ;
    } else {
        //回传已经存在
        $name = 0 ;
        echo json_encode($name);
    }
}



?>